package cn.com.lms.business.examRewrite.persistence.repository;

import cn.com.lms.business.examRewrite.persistence.entity.PaperReWrite;
import com.bnzj.core.persistence.repository.BaseRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface PaperReWriteDao extends BaseRepository<PaperReWrite,Long> {
    /**
     * 删除、批量删除操作
     * @param result
     * @param ids
     * @return
     */
    @Query(nativeQuery = true,value = "UPDATE bnz_exam_paper SET is_delete = :result WHERE id IN (:ids)")
    @Modifying
    Integer deleteReWrite(@Param("result") boolean result, @Param("ids") List<Long> ids);

    /**
     * 启用
     * @param result
     * @param ids
     * @return
     */
    @Query(nativeQuery = true,value = "UPDATE bnz_exam_paper SET is_enable = :result WHERE id = :ids")
    @Modifying
    Integer enableReWrite(@Param("result") boolean result, @Param("ids") List<Long> ids);

    /**
     * 禁用
     * @param result
     * @param ids
     * @return
     */
    @Query(nativeQuery = true,value = "UPDATE bnz_exam_paper SET is_enable = :result WHERE id = :ids")
    @Modifying
    Integer disableReWrite(@Param("result") boolean result, @Param("ids") List<Long> ids);

    /**
     * 通过id获取数据
     * @param id
     * @param result
     * @return
     */
    @Query(nativeQuery = true,value = "SELECT * from bnz_exam_paper WHERE id = ?1 AND is_delete = ?2")
    PaperReWrite getPaperReWriteById(Long id,Boolean result);
}
